#!/usr/bin/python2
import sys

if (len(sys.argv) != 2):
    print "Usage: {0} /path/to/t/mjin2".format(sys.argv[0])
    sys.exit(0)

dataDir = sys.argv[1] + "/Renderless"

import pymjin2

def printXMLTree(node, level = 0):
    for i in range(0, level):
        print " ",
    print node.name, " ", node.value
    for a in node.attrs:
        for i in range(0, level + 2):
            print " ",
        print "{0} = {1}".format(a.name, a.value)
    for n in node.nodes:
        printXMLTree(n, level + 1)

app = pymjin2.Application("Python Renderless", "log.html")
sl = pymjin2.StringList()
re = pymjin2.RegExp("abc(.*)")
if (re.match("Wow abc man", sl)):
    for a in sl:
        print a
print "Distribution:", pymjin2.distribution()
print "Version:", pymjin2.version()
resolver = app.pathResolver()
resolver.addSearchPath(dataDir)
cfg = pymjin2.ConfigFile(resolver.findFile("os-release"))
print cfg.str()

#app.logger().log("Logging from Python")
for a in resolver.searchPaths():
    print "search path:", a
xml = pymjin2.GameXML(resolver)
node = xml.loadAndDereference(resolver.findFile("mj.xml"))
printXMLTree(node)
itr = pymjin2.InputTranslator()
print itr.string(pymjin2.INPUT_KEY_X), "=", itr.id("INPUT_KEY_X")
# Translator.
translator = pymjin2.Translator("en")
pymjin2.loadTranslatorXML(translator, resolver.findFile("en.xml"))
pymjin2.loadTranslatorXML(translator, resolver.findFile("ru.xml"))
# Print translations.
print translator.tr("CANCEL")
print translator.id("Cancel")
print translator.tr("APPLY")
print translator.id("Apply")
translator.setDefaultLanguage("ru")
print translator.tr("CANCEL")
print translator.tr("APPLY")
# Should print English since no Russian is present.
print translator.tr("YES")
print translator.tr("INVALID_ID")
print translator.id("Invalid string")

